
#include "atomic_op_asm.h"

#if defined(_ARM_ARCH_6)

ENTRY_NP(__sync_fetch_and_add_8)
	push	{r4-r7}
	mov	ip, r0
#ifndef __ARM__EABI__
	mov	r3, r2
	mov	r2, r1
#endif
1:	ldrexd	r0, r1, [ip]		/* load old value */
	adds	TLO, LO, NLO		/* calculate new value */
	adcs	THI, HI, NHI		/* calculate new value */
	strexd	r6, r4, r5, [ip]	/* try to store */
	cmp	r6, #0			/*   succeed? */
	bne	1b			/*     no, try again */
#ifdef _ARM_ARCH_7
	dmb
#else
	mcr	p15, 0, r2, c7, c10, 5	/* data memory barrier */
#endif
	pop	{r4-r7}
	RET				/* return old value */
END(__sync_fetch_and_add_8)

CRT_ALIAS(__atomic_fetch_add_8,__sync_fetch_and_add_8)

#endif /* _ARM_ARCH_6 */
